package mapstruct;

import DTO.PeopleDTO;
import DTO.UserDTO;
import PO.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @ProjectName: util
 * @Package: mapstruct
 * @ClassName: ${TYPE_NAME}
 * @Description:
 * @Author: haifeng.mi
 * @CreateDate: 2018/9/21 10:51
 * @UpdateUser: haifeng.mi
 * @UpdateDate: 2018/9/21 10:51
 * @UpdateRemark: The modified content
 * @Version: 1.0
 * Copyright: Copyright (c) 2018
 */
@Mapper
public interface UserMapper {

    public static UserMapper MAPPER = Mappers.getMapper(UserMapper.class);


    /**
     * PO转DTO
     * @param user
     * @return
     */
    @Mappings({
            @Mapping(target = "userGeo",  ignore = true),
            @Mapping(target = "userRoleList",  ignore = true)
    })
    UserDTO userToUserDTO(User user);



    /**
     * PO转DTO
     * @param user
     * @return
     */
    List<UserDTO> userToUserDTOs(List<User> user);


    /**
     * PO转DTO
     * 其中一个字段名称不一致的场景
     * @param user
     * @return
     */
    @Mapping(target = "userId", source = "userLoginId")
    PeopleDTO userToPeopleDTO(final User user);


    /**
     * DTO转PO
     * @param userDTO
     * @return
     */
    User userDTOToUser(UserDTO userDTO);



}
